window.onload = function(){
let name = document.querySelector('#name');
let pwd = document.querySelector('#pwd');
let pwds = document.querySelector('#pwds');
let iphone = document.querySelector('#iphone');
let auth = document.querySelector('#auth');
let iphoneAuth = document.querySelector('#iphone_auth');
let check = document.querySelector('#check');
let btn = document.querySelector('.btn');
let tellAuth = document.querySelector('.tell_auth');


//点击事件 把账号名 和密码存入永久级存储中
btn.addEventListener('click',function(){
   localStorage.setItem('name',name.value);
   localStorage.setItem('pwd',pwd.value);
})
tellAuth.addEventListener('click',function(){
    let i = 3;
    let time=setInterval(function(){
    i--;
    tellAuth.innerHTML=`${i}`
    tellAuth.disabled=true;
    if(i<0){
    clearInterval(time)
    tellAuth.innerHTML=`获取验证码`
    tellAuth.disabled=false;
    }
    console.log(111);
    
    },1000)
    
    
    })




let nameReg = /^[a-zA-Z0-9_-]{4,16}$/;
let pwdReg = /^.*(?=.{6,})(?=.*\d)(?=.*[A-Z])(?=.*[a-z])(?=.*[!@#$%^&*? ]).*$/;
let iphoneReg = /^1[3-9][0-9]{9}$/;
let authReg = /^([0-9]|[a-z]|[A-Z]){4}$/;
    

    // 点击注册
    //监听事件-非空验证
    btn.addEventListener('click',function(){
        let num = true;
        if(name.value && pwd.value && pwds.value && iphone.value && auth.value && iphoneAuth.value && check.checked){
            num = true ;
        }else{
            num = false ;
        }
    //    console.log(num);
        // 不满足正则验证时，提醒用户
        if (nameReg.test(name.value) === false) {
            alert('用户名输入错误')
        } else if (pwdReg.test(pwd.value) === false) {
            alert('密码格式错误，大写 小写 特殊字符 组成的不少于6位的密码')
        } else if (iphoneReg.test(iphone.value) === false) {
            alert('请输入正确的手机号')
        } else if (authReg.test(auth.value) === false) {
            alert('验证码格式错误')
        } else if (authReg.test(iphoneAuth.value) === false) {
            alert('手机验证码格式错误')
        } else if (pwd.value != pwds.value) {
            alert('两次输入的密码不一致')
        } else if(check.checked!=true){
            console.log(check.checked);
             alert('请选择霸王条款')
        }else{
            setTimeout(function () {
                location.href = './index.html'
            }, 2000)
            alert('注册成功,请前往登录')
    }
    })




}